package com.csw.flink.transformation

import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala._

object Demo01Map {

  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment


    env.setParallelism(1)

    val ds: DataStream[String] = env.socketTextStream("master", 8888)

    //scala的写法  返回一个数组
    val ds2: DataStream[String] = ds.map(line => (line + ":csw"))

    //java的写法  使用匿名内部类
    var ds1: DataStream[String] = ds.map(new MapFunction[String, String] {
      override def map(t: String): String = {
        t + ":csw"
      }
    })
    ds1.print()


    /**
      *
      * flink程序没有转换算子和操作算子的区别
      * 但是最后需要 execute 启动flink的程序
      *
      */
    env.execute()

  }
}
